package com.can.entityDTO;

import com.can.common.constant.JsonResultEnum;

/**
 * @Description 返回实体类
 * @Author can
 * @Date 2018/8/28
 * @Version 1.0
 */
public class JsonResult {
    /** 返回码 **/
    private Integer resultCode;
    /** 错误信息，无错误信息就显示空 **/
    private String errorMsg;
    /** 返回数据 **/
    private Object data;

    public JsonResult() {
    }

    public JsonResult(JsonResultEnum jsonResultEnum){
        this.resultCode = jsonResultEnum.getCode();
        this.errorMsg = jsonResultEnum.getMsg();
    }

    public JsonResult(JsonResultEnum jsonResultEnum, String errorMsg){
        this(jsonResultEnum);
        this.errorMsg = errorMsg;
    }

    public static JsonResult createSuccess(Object data) {
        JsonResult jsonResult = new JsonResult(JsonResultEnum.SUCCESS);
        jsonResult.setData(data);
        return jsonResult;
    }

    public static JsonResult createError(String errorMsg){
        return new JsonResult(JsonResultEnum.EXECUTE_ERROR,errorMsg);
    }

    public Integer getResultCode() {
        return resultCode;
    }

    public void setResultCode(Integer resultCode) {
        this.resultCode = resultCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
